Download radio-0.3.tar.gz.
Update: radio.py-0.4 is now available.
I like listening to music and radio while working, and fortunately there are numerous ways to do that. Unfortunately, most ways that allow you to listen to radio are very resource-consuming memory hogs (such as listening to streaming media via web browsers) or very unfriendly to users (listening via mplayer, for example). So, I set out to find a way that would use as few system resources as possible while keeping it user-friendly. One other requirement I had was being able to do all that from the command line, so it would work great with GNU Screen and wouldn’t require an X server (if I worked without one).
I used mplayer for some time for listening to radio. I had a file with a list of web radio stream URLs, which I would copy and pass to mplayer -playlist. This method met two of the requirements (minimal resources and command-line interface), but wasn’t really user-friendly. So, I wrote a little wrapper script in Python around mplayer – radio.py. After a quick installation (download and extract the tar archive and copy radio.py somewhere in your PATH), radio.py will allow you to listen to stations easily, and it will also do a couple more things for you.
To listen to a station, just call radio.py with the station’s name; e.g., in the command line enter radio.py BBC1 to listen to BBC Radio 1. To view a list of known stations, run radio.py --list. Currently there aren’t many stations (just stations I thought were needed or that I listen to). You can easily edit radio.py to add new stations (the script is documented and very clear). If you do so, please write a comment or email me so I will be able to add those stations to the next release by default.
So, as you’ve seen, radio.py allows you to easily listen to radio, as easily as writing the station’s name. But, as I said, it can do more things that I thought should be in a radio script. It has both a sleep feature (that turns off the radio after a specified amount of time) and a wake-up feature (that starts the radio after a specified amount of time). These two features can be used together, and practically allow you to use radio.py as an alarm clock.
You can find more information about radio.py options by calling radio.py --help. I hope you will find this script as useful as I do.
Download:
radio-0.3.tar.gz.
maybe you should have some web page to list the radio stations and have an auto update option in the script 🙂
I was thinking about something similar, having an option to translate station names to URLs via a XML file on the web. For example you will call “radio.py -u STATION” and it will access some XML file and parse it instead of using it’s internal station list.
HI, I’ve modified a little your python script, to read from a file. I used the ConfigParser module of standar python, not XML. If you like I send you a mail with the modifications.
Bye.
Hi Nado, thanks for modifying the code. I’ve sent you an email with a reply.
Thanks for the awesome post, it helped me out a lot.
I’ve been having the same problems, but then I used Homebrew to install mplayer and it seems to be working better.
brew install mplayer